package com.example.pattern.memento;

/**
 * 原始对象，可以创建备忘录和从备忘录中恢复状态
 *
 * @author FM_南风
 * @date 2024/7/7
 */
public class Originator  {
	private String state;

	public void setState(String state) {
		this.state = state;
	}

	public String getState() {
		return state;
	}

	// 创建备忘录，保存当前状态
	public Memento saveStateToMemento() {
		return new Memento(state);
	}

	// 从备忘录中恢复状态
	public void restoreStateFromMemento(Memento memento) {
		state = memento.getSavedState();
	}
}
